package org.yzhang3.data.bean;

/**
 * all nodes are leaf nodes, which contain the symbol itself, the weight
 * (frequency of appearance) of the symbol and optionally, a link to a parent
 * node which makes it easy to read the code (in reverse) starting from a leaf
 * node.<br>
 * 
 * Internal nodes contain symbol weight, 
 * links to two child nodes and the optional link to a parent node. 
 * 
 * @author yzhang8015
 * 
 */
public class HuffmanNode extends Node implements Comparable<HuffmanNode> {

	/** frequency of <code>symbol</code>'s appearance */
	private int weight = -1;
	private int data;

	public HuffmanNode(int weight) {
		this.weight = weight;
	}
	
	public HuffmanNode(int weight, int data) {
		this.weight = weight;
		this.data = data;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}
	
	public int getData() {
		return data;
	}
	
	public void setData(int data) {
		this.data = data;
	}
	
	@Override
	public int compareTo(HuffmanNode o) {
		return this.weight - o.getWeight();
	}

	@Override
	public String toString() {
		return "HuffmanNode:{weight=" + weight + ",data=" + data + "}";
	}
	
}
